from google.appengine.ext import ndb
from google.appengine.ext import blobstore
from time import sleep


# Models
class Post(ndb.Model):
    title = ndb.StringProperty(required=True)
    date = ndb.DateTimeProperty(auto_now_add=True)
    text = ndb.TextProperty(required=True)
    tags = ndb.TextProperty(repeated=True)


class Photo(ndb.Model):
    image = ndb.StringProperty() #blobstore.BlobReferenceProperty()


class Tag(ndb.Model):
    pass
    #name =  ndb.StringProperty()#required=True


class Services(ndb.Model):
    """Parent for all service categories.
        Maybe can do without it
    """

    @classmethod
    def _pre_delete_hook(cls, key):
        for x in ServiceCategory.query(ancestor=key).fetch():
            print x
            x.key.delete()
        print 'Deleting complited!'


class ServiceCategory(ndb.Model):
    """ Parent for all Service types
    """
    name = ndb.StringProperty(required=True)

    @classmethod
    def _pre_delete_hook(cls, key):
        for x in ServiceType.query(ancestor=key).fetch():
            x.key.delete()
        sleep(1)

class ServiceType(ndb.Model):
    """ Service type
    """
    name = ndb.StringProperty(required=True)
    description = ndb.TextProperty(required=True)
